package com.zhehekeji.opsys.api.service.manager;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.cxf.common.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhehekeji.opsys.api.code.LuckySignupResultCode;
import com.zhehekeji.opsys.api.common.util.DateFormatUtil;
import com.zhehekeji.opsys.api.conf.Config;
import com.zhehekeji.opsys.api.enm.ThemeMovieType;
import com.zhehekeji.opsys.api.enm.ThemeUserType;
import com.zhehekeji.opsys.api.entity.TTheme;
import com.zhehekeji.opsys.api.entity.TThemeMovie;
import com.zhehekeji.opsys.api.entity.TThemeUser;
import com.zhehekeji.opsys.api.resp.GetThemeListResp;
import com.zhehekeji.opsys.api.resp.GetThemeMovieListResp;
import com.zhehekeji.opsys.api.resp.GetThemeMovieResp;
import com.zhehekeji.opsys.api.resp.GetThemeResp;
import com.zhehekeji.opsys.api.resp.GetThemeUserListResp;
import com.zhehekeji.opsys.api.resp.LuckySignupResp;
import com.zhehekeji.opsys.api.service.CommonService;
import com.zhehekeji.opsys.api.service.validate.ThemeMovieValidate;
import com.zhehekeji.opsys.api.service.validate.ThemeProductValidate;
import com.zhehekeji.opsys.api.service.validate.ThemeValidate;
import com.zhehekeji.opsys.api.service.validate.ValidateRets;
import com.zhehekeji.opsys.api.service.validate.args.ThemeMovieValidateArgs;
import com.zhehekeji.opsys.api.service.validate.args.ThemeProductValidateArgs;
import com.zhehekeji.opsys.api.service.validate.args.ThemeValidateArgs;

/**
 * @ClassName ThemeManagerService
 * @Description TODO
 * @author chenweiliu chenwei.liu@163.com
 * @date 2016-5-25   上午11:19:40
 */
@Service
public class ThemeManagerService extends CommonService{
	
	private final static Logger logger = LoggerFactory.getLogger(ThemeManagerService.class);
	
	@Autowired
	private ThemeValidate themeValidate;
	@Autowired
	private ThemeMovieValidate themeMovieValidate;
	@Autowired
	private ThemeProductValidate themeProductValidate;
	@Autowired
	private Config config;
	
	public GetThemeResp getTheme(String themeCode) {
		
		GetThemeResp resp = new GetThemeResp();
		if (StringUtils.isEmpty(themeCode)){
			logger.error("专题编码非法！");
			resp.setResultCode(LuckySignupResultCode.PARAMETER_IS_NOT_LEGAL);
			resp.setResultDesc("专题编码非法！");
			return resp;
		}
		try {
			TTheme tmpTTheme = entityDao.get(TTheme.class, "code=?1", new Object[]{themeCode});
			if (tmpTTheme == null){
				logger.error("专题不存在，专题编码非法！");
				resp.setResultCode(LuckySignupResultCode.PARAMETER_IS_NOT_LEGAL);
				resp.setResultDesc("专题不存在，专题编码非法！");
				return resp;
			}
			Integer tmpStatus = tmpTTheme.getStatus();
			if (tmpStatus == 0){
				logger.error("专题已经停用！");
				resp.setResultCode(LuckySignupResultCode.THEME_HAS_BEEN_STOPPED);
				resp.setResultDesc("专题已经停用！");
				return resp;
			}
			resp.setCode(themeCode);
			resp.setCpCode(tmpTTheme.getCpCode());
			resp.setEndTime(DateFormatUtil.format(tmpTTheme.getEndTime(), "yyyy-MM-dd HH:mm:ss"));
			resp.setLimitNum(tmpTTheme.getLimitNum());
			resp.setName(tmpTTheme.getName());
			resp.setPartinTimes(tmpTTheme.getPartinTimes());
			resp.setProfile(tmpTTheme.getProfile());
			resp.setStartTime(DateFormatUtil.format(tmpTTheme.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
			if (!StringUtils.isEmpty(tmpTTheme.getThemePoster())){
				resp.setThemePoster(getHttpUrl(tmpTTheme.getThemePoster()));
			}
			if (!StringUtils.isEmpty(tmpTTheme.getThemePosterhd())){
				resp.setThemePosterhd(getHttpUrl(tmpTTheme.getThemePosterhd()));
			}
			logger.info("获取专题信息成功");
		} catch (Exception e) {
			logger.error("程序异常，" + e.getMessage(), e);
			resp.setResultCode(LuckySignupResultCode.APPLICATION_EXCEPTION);
			resp.setResultDesc("程序异常");
		}
		return resp;
		
	}

	public GetThemeListResp getThemeList(long cpCode, int firstIndex, int maxResult) {
		GetThemeListResp resp = new GetThemeListResp();
		String tmpWhereJpql = null;
		if (cpCode != -1){
			tmpWhereJpql = "o.cpCode=" +cpCode + " and o.status=1";
		}else{
			tmpWhereJpql = "o.status=1";
		}
		try {
			String tmpCountHql = "select count(o.id) as count from TTheme o where " + tmpWhereJpql;
			List<Map<String, Object>> tmpListMapCount = entityDao.getScrollDataByHql(tmpCountHql, null, -1, -1);
			int tmpIntCount = 0;
			if (tmpListMapCount != null && !tmpListMapCount.isEmpty()){
				Map<String, Object> tmpMapCount = tmpListMapCount.get(0);
				Long tmpLongCount = (Long) tmpMapCount.get("count");
				tmpIntCount = tmpLongCount.intValue();
			}
			if(tmpIntCount <= 0) return resp;
			 
			LinkedHashMap<String, String> orderBy = new LinkedHashMap<String, String>();
			orderBy.put("createTime", "asc");
			List<TTheme> tmpListTTheme = entityDao.getScrollData(TTheme.class, firstIndex, maxResult, tmpWhereJpql, null, orderBy);
			if (tmpListTTheme == null || tmpListTTheme.isEmpty()) return resp;
			List<GetThemeListResp.ThemeInfo> tmpListThemeInfo = new ArrayList<GetThemeListResp.ThemeInfo>();
			GetThemeListResp.ThemeInfo tmpThemeInfo;
			for (TTheme tmpTTheme : tmpListTTheme){
				tmpThemeInfo = new GetThemeListResp.ThemeInfo();
				tmpThemeInfo.setCode(tmpTTheme.getCode());
				tmpThemeInfo.setCpCode(tmpTTheme.getCpCode());
				tmpThemeInfo.setEndTime(DateFormatUtil.format(tmpTTheme.getEndTime(), "yyyy-MM-dd HH:mm:ss"));
				tmpThemeInfo.setLimitNum(tmpTTheme.getLimitNum());
				tmpThemeInfo.setName(tmpTTheme.getName());
				tmpThemeInfo.setPartinTimes(tmpTTheme.getPartinTimes());
				tmpThemeInfo.setProfile(tmpTTheme.getProfile());
				tmpThemeInfo.setStartTime(DateFormatUtil.format(tmpTTheme.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
				if (!StringUtils.isEmpty(tmpTTheme.getThemePoster())){
					tmpThemeInfo.setThemePoster(getHttpUrl(tmpTTheme.getThemePoster()));
				}
				if (!StringUtils.isEmpty(tmpTTheme.getThemePosterhd())){
					tmpThemeInfo.setThemePosterhd(getHttpUrl(tmpTTheme.getThemePosterhd()));
				}
				
				tmpListThemeInfo.add(tmpThemeInfo);
			}
			resp.setThemeInfos(tmpListThemeInfo);
			resp.setRecordSize(tmpIntCount);
			logger.info("获取专题列表成功");
		} catch (Exception e) {
			logger.error("获取专题列表失败，程序异常，" + e.getMessage(), e);
			resp.setResultCode(LuckySignupResultCode.APPLICATION_EXCEPTION);
			resp.setResultDesc("获取专题列表失败，程序异常！");
		}
		return resp;
	}
	
	public GetThemeMovieResp getThemeMovie(String movieCode){
		GetThemeMovieResp resp = new GetThemeMovieResp();
		if (StringUtils.isEmpty(movieCode)){
			logger.error("影片编码非法！");
			resp.setResultCode(LuckySignupResultCode.PARAMETER_IS_NOT_LEGAL);
			resp.setResultDesc("影片编码非法！");
			return resp;
		}
		try {
			TThemeMovie tmpTThemeMovie = entityDao.get(TThemeMovie.class, "code=?1", new Object[]{movieCode});
			if (tmpTThemeMovie == null){
				logger.error("影片不存在，影片编码非法！");
				resp.setResultCode(LuckySignupResultCode.PARAMETER_IS_NOT_LEGAL);
				resp.setResultDesc("影片不存在，影片编码非法！");
				return resp;
			}
			Integer tmpStatus = tmpTThemeMovie.getStatus();
			if (tmpStatus == 0){
				logger.error("影片已经停用！");
				resp.setResultCode(LuckySignupResultCode.MOVIE_HAS_BEEN_STOPPED);
				resp.setResultDesc("影片已经停用！");
				return resp;
			}
			if (!StringUtils.isEmpty(tmpTThemeMovie.getPoster())){
				resp.setPoster(getHttpUrl(tmpTThemeMovie.getPoster()));
			}
			if (!StringUtils.isEmpty(tmpTThemeMovie.getPosterhd())){
				resp.setPosterhd(getHttpUrl(tmpTThemeMovie.getPosterhd()));
			}
			resp.setCinema(tmpTThemeMovie.getCinema());
			resp.setCode(tmpTThemeMovie.getCode());
			resp.setName(tmpTThemeMovie.getName());
			resp.setProfile(tmpTThemeMovie.getProfile());
			resp.setRegistNum(tmpTThemeMovie.getRegistNum());
			resp.setRelCode(tmpTThemeMovie.getRelCode());
			resp.setRelCodehd(tmpTThemeMovie.getRelCodehd());
			resp.setRelPrevueCode(tmpTThemeMovie.getRelPrevueCode());
			resp.setRelPrevueCodehd(tmpTThemeMovie.getRelPrevueCodehd());
			resp.setShowAddress(tmpTThemeMovie.getShowAddress());
			resp.setType(tmpTThemeMovie.getType());
			resp.setShowTime(DateFormatUtil.format(tmpTThemeMovie.getShowTime(), "yyyy-MM-dd HH:mm:ss"));
			resp.setShowTimeFormat(DateFormatUtil.format(tmpTThemeMovie.getShowTime(), "MM月dd日"));
			logger.info("获取专题信息成功");
		} catch (Exception e) {
			logger.error("程序异常，" + e.getMessage(), e);
			resp.setResultCode(LuckySignupResultCode.APPLICATION_EXCEPTION);
			resp.setResultDesc("程序异常");
		}
		return resp;
	}
	public GetThemeMovieListResp getThemeMovieList(String themeCode, int firstIndex, int maxResult) {
		GetThemeMovieListResp resp = new GetThemeMovieListResp();
		String resultDesc = String.format("专题活动[%s]获取专题影片列表成功！", themeCode);
		try{
			if (StringUtils.isEmpty(themeCode)){
				resultDesc = String.format("专题活动[%s]获取专题影片列表失败，编码非法！", themeCode);
				logger.error(resultDesc);
				resp.setResultCode(LuckySignupResultCode.PARAMETER_IS_NOT_LEGAL);
				resp.setResultDesc(resultDesc);
				return resp;
			}
			String tmpSql = "select count(o.id) as count from TThemeMovie o where o.ttheme.code=? and o.status=1";
			List<Map<String, Object>> tmpListMapCount = entityDao.getScrollDataByHql(tmpSql, new Object[]{themeCode}, -1, -1);
			int tmpIntCount = 0;
			if (tmpListMapCount != null && !tmpListMapCount.isEmpty()){
				Map<String, Object> tmpMapCount = tmpListMapCount.get(0);
				Long tmpLongCount = (Long) tmpMapCount.get("count");
				tmpIntCount = tmpLongCount.intValue();
			}
			if (tmpIntCount <= 0) return resp;
			LinkedHashMap<String, String> orderBy = new LinkedHashMap<String, String>();
			orderBy.put("sequence", "desc");
			orderBy.put("type", "asc");
			List<TThemeMovie> tmpListTThemeMovie = entityDao.getScrollData(TThemeMovie.class, firstIndex, maxResult, 
					"o.ttheme.code=?1 and o.status=1", 
					new Object[]{themeCode}, orderBy);
			if (tmpListTThemeMovie == null || tmpListTThemeMovie.isEmpty()) return resp;
			List<GetThemeMovieListResp.ThemeMovieInfo> tmpListThemeMovieInfo = new ArrayList<GetThemeMovieListResp.ThemeMovieInfo>();
			GetThemeMovieListResp.ThemeMovieInfo tmpThemeMovieInfo;
			for (TThemeMovie tmpTThemeMovie : tmpListTThemeMovie){
				tmpThemeMovieInfo = new GetThemeMovieListResp.ThemeMovieInfo();
				if (!StringUtils.isEmpty(tmpTThemeMovie.getPoster())){
					tmpThemeMovieInfo.setPoster(getHttpUrl(tmpTThemeMovie.getPoster()));
				}
				if (!StringUtils.isEmpty(tmpTThemeMovie.getPosterhd())){
					tmpThemeMovieInfo.setPosterhd(getHttpUrl(tmpTThemeMovie.getPosterhd()));
				}
				tmpThemeMovieInfo.setCinema(tmpTThemeMovie.getCinema());
				tmpThemeMovieInfo.setCode(tmpTThemeMovie.getCode());
				tmpThemeMovieInfo.setName(tmpTThemeMovie.getName());
				tmpThemeMovieInfo.setProfile(tmpTThemeMovie.getProfile());
				tmpThemeMovieInfo.setRegistNum(tmpTThemeMovie.getRegistNum());
				tmpThemeMovieInfo.setRelCode(tmpTThemeMovie.getRelCode());
				tmpThemeMovieInfo.setRelCodehd(tmpTThemeMovie.getRelCodehd());
				tmpThemeMovieInfo.setRelPrevueCode(tmpTThemeMovie.getRelPrevueCode());
				tmpThemeMovieInfo.setRelPrevueCodehd(tmpTThemeMovie.getRelPrevueCodehd());
				tmpThemeMovieInfo.setShowAddress(tmpTThemeMovie.getShowAddress());
				tmpThemeMovieInfo.setType(tmpTThemeMovie.getType());
				tmpThemeMovieInfo.setShowTime(DateFormatUtil.format(tmpTThemeMovie.getShowTime(), "yyyy-MM-dd HH:mm:ss"));
				tmpThemeMovieInfo.setShowTimeFormat(DateFormatUtil.format(tmpTThemeMovie.getShowTime(), "MM月dd日"));
				tmpListThemeMovieInfo.add(tmpThemeMovieInfo);
			}
			resp.setRecordSize(tmpIntCount);
			resp.setThemeMovieInfos(tmpListThemeMovieInfo);
			logger.info(resultDesc);
		}catch(Exception e){
			resultDesc = String.format("专题活动[%s]获取专题影片失败，程序异常！", themeCode);
			logger.error(resultDesc, e);
			resp.setResultCode(LuckySignupResultCode.APPLICATION_EXCEPTION);
			resp.setResultDesc(resultDesc);
		}
		return resp;
	}
	@Transactional
	public LuckySignupResp luckySignup(String movieCode, String productID, String userID, String userPhone, int updatePhone) {
		LuckySignupResp resp = new LuckySignupResp();
		resp.setUserID(userID);
		resp.setUserPhone(userPhone);
		Date currentDate = new Date();
		String resultDesc = String.format("账号[%s]报名观影[%s]成功！", userID, movieCode);
		try{
			//参数为空校验
			if (StringUtils.isEmpty(movieCode) || StringUtils.isEmpty(userID) || StringUtils.isEmpty(userPhone)){
				resultDesc = "报名失败，参数非法！";
				logger.error(resultDesc);
				resp.setResultCode(LuckySignupResultCode.PARAMETER_IS_NOT_LEGAL);
				resp.setResultDesc(resultDesc);
				return resp;
			}
			//验证专题影片有效性
			ValidateRets<TThemeMovie>  tmpTThemeMovieValidateRets = themeMovieValidate.validate(new ThemeMovieValidateArgs(resp, movieCode));
			if (!tmpTThemeMovieValidateRets.isSuccess()) return resp;
			TThemeMovie tmpTThemeMovie = tmpTThemeMovieValidateRets.getEntity();
			//验证专题活动有效性
			TTheme tmpTTheme = tmpTThemeMovie.getTtheme();
			if (tmpTTheme == null){
				resultDesc = String.format("账号[%s]报名观影[%s]失败，专题活动不存在！", userID, movieCode);
				logger.error(resultDesc);
				resp.setResultCode(LuckySignupResultCode.THEME_DOES_NOT_EXIST);
				resp.setResultDesc(resultDesc);
				return resp;
			}
			//验证投票活动有效性
			ValidateRets<TTheme> tmpTThemeValidateRets = themeValidate.validate(new ThemeValidateArgs(resp, tmpTTheme, currentDate));
			if (!tmpTThemeValidateRets.isSuccess()) return resp;
			
			//验证专题产品
			ValidateRets<List<String>> tmpTThemeProductValidateRets = themeProductValidate.validate(new ThemeProductValidateArgs(resp, movieCode, productID, tmpTTheme.getId()));
			if (!tmpTThemeProductValidateRets.isSuccess()) return resp;
			
			//参与报名次数，小于等于专题下可观影片数量
			int tmpPartinTimes = tmpTTheme.getPartinTimes() == null ? 1 : tmpTTheme.getPartinTimes();
			String tmpSql = "select count(o.id) as count from TThemeMovie o where o.ttheme.code=? and o.type=? and o.status=1";
			List<Map<String, Object>> tmpListMapCount = entityDao.getScrollDataByHql(tmpSql, 
					new Object[]{tmpTTheme.getCode(), ThemeMovieType.VIEW.getType()}, -1, -1);
			int tmpIntCount = 0;
			if (tmpListMapCount != null && !tmpListMapCount.isEmpty()){
				Map<String, Object> tmpMapCount = tmpListMapCount.get(0);
				Long tmpLongCount = (Long) tmpMapCount.get("count");
				tmpIntCount = tmpLongCount.intValue();
			}
			if (tmpIntCount <= 0){
				resultDesc = String.format("账号[%s]报名观影[%s]失败，专题活动下无可观影片！", userID, movieCode);
				logger.error(resultDesc);
				resp.setResultCode(LuckySignupResultCode.THEME_HAS_NO_VIEW_MOVIE);
				resp.setResultDesc(resultDesc);
				return resp;
			}
			if (tmpPartinTimes > tmpIntCount){
				tmpPartinTimes = tmpIntCount;
			}
			//获取设备已报名观影次数
			tmpSql = "select count(o.id) as count from TThemeUser o where o.ttheme.code=? and o.userId=?";
			tmpListMapCount = entityDao.getScrollDataByHql(tmpSql, 
					new Object[]{tmpTTheme.getCode(), userID}, -1, -1);
			tmpIntCount = 0;
			if (tmpListMapCount != null && !tmpListMapCount.isEmpty()){
				Map<String, Object> tmpMapCount = tmpListMapCount.get(0);
				Long tmpLongCount = (Long) tmpMapCount.get("count");
				tmpIntCount = tmpLongCount.intValue();
			}
			TThemeUser tmpTThemeUser = entityDao.get(TThemeUser.class, "o.movieCode=?1 and o.userId=?2",
					new Object[]{movieCode, userID});
			
			/**
			 * 已报名，更新最后一次提交的报名手机号
			 */
			if (tmpTThemeUser != null){
				resultDesc = String.format("账号[%s]报名观影[%s]失败，已报名！", userID, movieCode);
				logger.error(resultDesc);
				String tmpUserPhone = tmpTThemeUser.getUserPhone();
				if (StringUtils.isEmpty(tmpUserPhone)){
					tmpTThemeUser.setUserPhone(userPhone);
					entityDao.update(tmpTThemeUser);
				}else{
					if (!tmpUserPhone.equals(userPhone) && updatePhone != 0){
						tmpTThemeUser.setUserPhone(userPhone);
						entityDao.update(tmpTThemeUser);
					}
				}
				//返回报名手机号
				resp.setUserPhone(tmpTThemeUser.getUserPhone());
				resp.setResultCode(LuckySignupResultCode.HAS_BEEN_SIGNUP);
				resp.setResultDesc(resultDesc);
				return resp;
			}
			
			if (tmpPartinTimes <= tmpIntCount ){
				resultDesc = String.format("账号[%s]报名观影[%s]失败，机会已用完！", userID, movieCode);
				logger.error(resultDesc);
				resp.setResultCode(LuckySignupResultCode.CHANCE_HAS_BEEN_FINISHED);
				resp.setResultDesc(resultDesc);
				return resp;
			}
			
			//保存报名记录
			tmpTThemeUser = new TThemeUser();
			tmpTThemeUser.setCpCode(tmpTTheme.getCpCode());
			tmpTThemeUser.setMovieCode(movieCode);
			tmpTThemeUser.setMovieName(tmpTThemeMovie.getName());
			tmpTThemeUser.setSignupTime(currentDate);
			tmpTThemeUser.setStatus(0);//未通知
			tmpTThemeUser.setTtheme(tmpTTheme);
			tmpTThemeUser.setUserId(userID);
			tmpTThemeUser.setUserPhone(userPhone);
			entityDao.saveObj(tmpTThemeUser);
			//更新报名人数
			int tmpRegistNum = tmpTThemeMovie.getRegistNum() == null ? 0 : tmpTThemeMovie.getRegistNum();
			tmpRegistNum = tmpRegistNum + 1;
			tmpTThemeMovie.setRegistNum(tmpRegistNum);
			tmpTThemeMovie.setUpdateTime(currentDate);
			entityDao.update(tmpTThemeMovie);
			resp.setMovieCode(movieCode);
			resp.setMovieName(tmpTThemeMovie.getName());
			resp.setSignupNum(tmpRegistNum);
			logger.info(resultDesc);
		}catch(Exception e){
			resultDesc = String.format("设备[%s]账号[%s]报名观影[%s]失败，程序异常！",userID);
			logger.error(resultDesc , e);
			resp.setResultCode(LuckySignupResultCode.APPLICATION_EXCEPTION);
			resp.setResultDesc(resultDesc);
		}
		return resp;
	}
	
	public GetThemeUserListResp getThemeUserList(String themeCode, int type, int firstIndex, int maxResult) {
		
		GetThemeUserListResp resp = new GetThemeUserListResp();
		String resultDesc = String.format("专题活动[%s]获取参与用户成功！", themeCode);
		try{
			if (StringUtils.isEmpty(themeCode)){
				resultDesc = String.format("专题活动[%s]获取参与用户失败，编码非法！", themeCode);
				logger.error(resultDesc);
				resp.setResultCode(LuckySignupResultCode.PARAMETER_IS_NOT_LEGAL);
				resp.setResultDesc(resultDesc);
				return resp;
			}
			String tmpSql = "select count(o.id) as count from TThemeUser o where";
			String whereSql = " o.ttheme.code=?";
			String whereJpql = "o.ttheme.code=?1";
			if (type == ThemeUserType.UN_NOTICE.getType()){
				whereSql = whereSql + " and o.status=0";
				whereJpql = whereJpql + " and o.status=0";
			}else if (type == ThemeUserType.ON_NOTICE.getType()){
				whereSql = whereSql + " and o.status=1";
				whereJpql = whereJpql + " and o.status=1";
			}
			tmpSql = tmpSql + whereSql;
			List<Map<String, Object>> tmpListMapCount = entityDao.getScrollDataByHql(tmpSql, new Object[]{themeCode}, -1, -1);
			int tmpIntCount = 0;
			if (tmpListMapCount != null && !tmpListMapCount.isEmpty()){
				Map<String, Object> tmpMapCount = tmpListMapCount.get(0);
				Long tmpLongCount = (Long) tmpMapCount.get("count");
				tmpIntCount = tmpLongCount.intValue();
			}
			if (tmpIntCount <= 0) return resp;
			LinkedHashMap<String, String> orderBy = new LinkedHashMap<String, String>();
			orderBy.put("signupTime", "desc");
			List<TThemeUser> tmpListTThemeUser = entityDao.getScrollData(TThemeUser.class, firstIndex, maxResult, 
					whereJpql, new Object[]{themeCode}, orderBy);
			if (tmpListTThemeUser == null || tmpListTThemeUser.isEmpty()) return resp;
			List<GetThemeUserListResp.ThemeUserInfo> tmpListThemeMovieInfo = new ArrayList<GetThemeUserListResp.ThemeUserInfo>();
			GetThemeUserListResp.ThemeUserInfo tmpThemeUserInfo;
			for (TThemeUser tmpTThemeUser : tmpListTThemeUser){
				tmpThemeUserInfo = new GetThemeUserListResp.ThemeUserInfo();
				tmpThemeUserInfo.setMovieCode(tmpTThemeUser.getMovieCode());
				tmpThemeUserInfo.setMovieName(tmpTThemeUser.getMovieName());
				tmpThemeUserInfo.setSignupTime(DateFormatUtil.format(tmpTThemeUser.getSignupTime(), "yyyy-MM-dd HH:mm:ss"));
				tmpThemeUserInfo.setStbID(tmpTThemeUser.getStbId());
				tmpThemeUserInfo.setUserID(tmpTThemeUser.getUserId());
				tmpThemeUserInfo.setUserPhone(tmpTThemeUser.getUserPhone());
				tmpListThemeMovieInfo.add(tmpThemeUserInfo);
			}
			resp.setRecordSize(tmpIntCount);
			resp.setThemeUserInfos(tmpListThemeMovieInfo);
			logger.info(resultDesc);
		}catch(Exception e){
			resultDesc = String.format("专题活动[%s]获取参与用户失败，程序异常！", themeCode);
			logger.error(resultDesc, e);
			resp.setResultCode(LuckySignupResultCode.APPLICATION_EXCEPTION);
			resp.setResultDesc(resultDesc);
		}
		return resp;
		
	}
}

